package cn.xclink.kernel.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import cn.xclink.common.entity.BaseEntity;

@Table(name = "sys_resource")
public class Resource  extends BaseEntity {

	private static final long serialVersionUID = 206867161356401645L;

	@Id
	@Column(name = "resource_id")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long resourceId;

	@Column(name = "resource_name")
	private String resourceName;

	@Column(name = "resource_type_code")
	private String resourceTypeCode;

	@Column(name = "resource_url")
	private String resourceUrl;

	@Column(name = "parent_id")
	private Long parentId;

	@Column(name = "parent_ids")
	private String parentIds;

	@Column(name = "resource_permission")
	private String resourcePermission;

	private String available;

	@Column(name = "create_by")
	private Long createBy;

	@Column(name = "last_update_by")
	private Long lastUpdateBy;

	@Column(name = "create_time")
	private Date createTime;

	@Column(name = "last_update_time")
	private Date lastUpdateTime;
	
	@Transient
	private Boolean checked = false;
	
	@Transient
	private String[] resourceIds;
	
	public Boolean getChecked() {
		return checked;
	}

	public void setChecked(Boolean checked) {
		this.checked = checked;
	}

	public String[] getResourceIds() {
		return resourceIds;
	}

	public void setResourceIds(String[] resourceIds) {
		this.resourceIds = resourceIds;
	}

	/**
	 * @return resource_id
	 */
	public Long getResourceId() {
		return resourceId;
	}

	/**
	 * @param resourceId
	 */
	public void setResourceId(Long resourceId) {
		this.resourceId = resourceId;
	}

	/**
	 * @return resource_name
	 */
	public String getResourceName() {
		return resourceName;
	}

	/**
	 * @param resourceName
	 */
	public void setResourceName(String resourceName) {
		this.resourceName = resourceName;
	}

	public String getResourceTypeCode() {
		return resourceTypeCode;
	}

	public void setResourceTypeCode(String resourceTypeCode) {
		this.resourceTypeCode = resourceTypeCode;
	}

	/**
	 * @return resource_url
	 */
	public String getResourceUrl() {
		return resourceUrl;
	}

	/**
	 * @param resourceUrl
	 */
	public void setResourceUrl(String resourceUrl) {
		this.resourceUrl = resourceUrl;
	}

	/**
	 * @return parent_id
	 */
	public Long getParentId() {
		return parentId;
	}

	/**
	 * @param parentId
	 */
	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	/**
	 * @return parent_ids
	 */
	public String getParentIds() {
		return parentIds;
	}

	/**
	 * @param parentIds
	 */
	public void setParentIds(String parentIds) {
		this.parentIds = parentIds;
	}

	/**
	 * @return resource_permission
	 */
	public String getResourcePermission() {
		return resourcePermission;
	}

	/**
	 * @param resourcePermission
	 */
	public void setResourcePermission(String resourcePermission) {
		this.resourcePermission = resourcePermission;
	}

	/**
	 * @return available
	 */
	public String getAvailable() {
		return available;
	}

	/**
	 * @param available
	 */
	public void setAvailable(String available) {
		this.available = available;
	}

	/**
	 * @return create_by
	 */
	public Long getCreateBy() {
		return createBy;
	}

	/**
	 * @param createBy
	 */
	public void setCreateBy(Long createBy) {
		this.createBy = createBy;
	}

	/**
	 * @return last_update_by
	 */
	public Long getLastUpdateBy() {
		return lastUpdateBy;
	}

	/**
	 * @param lastUpdateBy
	 */
	public void setLastUpdateBy(Long lastUpdateBy) {
		this.lastUpdateBy = lastUpdateBy;
	}

	/**
	 * @return create_time
	 */
	public Date getCreateTime() {
		return createTime;
	}

	/**
	 * @param createTime
	 */
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	/**
	 * @return last_update_time
	 */
	public Date getLastUpdateTime() {
		return lastUpdateTime;
	}

	/**
	 * @param lastUpdateTime
	 */
	public void setLastUpdateTime(Date lastUpdateTime) {
		this.lastUpdateTime = lastUpdateTime;
	}

	public boolean isRootNode() {
		if(parentId!=null){
			return parentId == -1;
		}else{
			return false;
		}
	}
	
	public String makeSelfAsParentIds() {
		return getParentIds() + getResourceId() + "/";
	}
}